package whu.cn.whushare.ui.main.search;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidplus.ui.ToastManager;
import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import whu.cn.whushare.R;
import whu.cn.whushare.bean.User;
import whu.cn.whushare.common.ImageWorkerManager;
import whu.cn.whushare.common.UserManager;
import whu.cn.whushare.ui.common.MainReShowFragment;
import whu.cn.whushare.ui.main.activity.ActivityListActivity;
import whu.cn.whushare.ui.main.known.InviteAnswerActivity;
import whu.cn.whushare.ui.main.known.QuestionListActivity;
import whu.cn.whushare.ui.main.my.LoginActivity;

/**
 * 文件名：SearchFragment
 * 描 述：
 * 作 者：胡平平
 * 时 间：2014/12/11
 */
public class SearchFragment extends MainReShowFragment implements View.OnClickListener {
    @ViewMapping(id = R.id.vip_search)          //获取“会员搜索”框
    private TextView mVip;
    @ViewMapping(id = R.id.question_search)     //获取“问题搜索”框
    private TextView mQuestion;
    @ViewMapping(id = R.id.resource_search)     //获取“活动搜索”框
    private TextView mResource;
    @ViewMapping(id = R.id.paper_search)        //获取“话题搜索”框
    private TextView mpaper;

    @Override
    /**
     * 为SearchFragment设置布局文件
     * @param inflater - 布局文件过滤器，通过其inflate方法获得与当前fragment相匹配的布局文件
     * @param container - 父控件
     * @param savedInstanceState - 保存的上下文状态信息
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        initParams();
        View root = inflater.inflate(R.layout.search_layout, container, false);
        initViews(root);
        return root;
    }

    //参数初始化
    private void initParams() {

    }

    //初始化控件
    private void initViews(View root) {
        ViewMappingUtil.mapView(this, root);
        getTopBarWithoutBack(root,R.id.top_bar);
        mTopBar.title.setText(R.string.search_total);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initActions();
    }

    //操作初始化
    private void initActions() {
       mVip.setOnClickListener(this);
       mQuestion.setOnClickListener(this);
       mResource.setOnClickListener(this);

    }

    @Override
    /**
     * 当发生控件点击事件时调用该方法，对相应的点击事件进行处理
     * 当发生点击事件的控件为“会员搜索”框时，从SearchUserActivity获取信息
     * 当发生点击事件的控件为“问题搜索”框时，从QuestionListActivity获取信息
     * 当发生点击事件的控件为“活动搜索”框时，从ActivityListActivity获取信息
     * @param v - 发生点击事件的控件
     */
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.vip_search:
                startActivityForResult(SearchUserActivity.getStartIntent(getActivity()),1);
                break;
            case R.id.question_search:
                startActivityForResult(QuestionListActivity.getStartIntent(getActivity(),"question"),1);
                break;
            case R.id.resource_search:
                startActivityForResult(ActivityListActivity.getStartIntent(getActivity(),"activity"),1);
            default:
                break;
        }




    }
}
